package com.train.lookup;

import java.util.Arrays;

public class InsertVal{
    public static void main(String[] args){
        int[] arr=new int[100];
        for(int i=0;i<100;i++)
        {
            arr[i]=i+1;
        }
        System.out.println(Arrays.toString(arr));
        int index=insertVal(arr,0,arr.length-1,99);
        System.out.println(index);
    }
    public static int insertVal(int[] arr,int left,int right,int val){
        if(left>right||val<arr[left]||val>arr[right])
            return -1;
        int middle=left+(right-left)*(val-arr[left])/(arr[right]-arr[left]);
        if(val>arr[middle]){
            return insertVal(arr,middle+1,right,val);
        }else if(val<arr[middle]){
            return insertVal(arr,left,middle-1,val);
        }else{
            return middle;
        }
    }
}